<?php
// +--------------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:17090888854>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * Music
 */
namespace Music\Controller;
use Music\Controller\PublicController;

/**
 *
 */
class PhoneController extends PublicController{
	
	
	/**
	 * LOTE首页
	 */
    public function Index(){
		$m_cms_content = M('cms_content');
		//轮播图
		$map['form_id'] = 0;
		$map['type'] = get_cms_model_conf('CMS_CAROUSELCLASS');
		$map['status'] = 1;
		$lista = $m_cms_content->where($map)->order('sort desc')->select();
		//获得下级分类即商品数量
		foreach($lista as $i=>$k){
			$down_map['form_id'] = $lista[$i]['id'];
			$down_map['type'] = get_cms_model_conf('CMS_CAROUSEL');
			$down_map['status']  =1;
			$down_list = $m_cms_content->where($down_map)->order('sort desc')->limit(3)->select();
			
			$lista[$i]['down'] = $down_list;
		}
		
		$map['type'] = 15;//解决方案
		$scheme = $m_cms_content->where($map)->order("sort desc")->limit(3)->select();
		foreach($scheme as $i=>$k){
			$scheme[$i]['img'] = $lista[0]['down'][$i]['img'];
		}
		//dump($scheme);die;
		$this->assign("scheme",$scheme);
		
		$map['type'] = 17;//产品介绍
		$product = $m_cms_content->where($map)->order("sort desc")->limit(3)->select();
		$this->assign("product",$product);
		
		$map['type'] = 13;//新闻
		$new = $m_cms_content->where($map)->order("sort desc")->limit(3)->select();
		foreach($new as $i=>$v){
			$map['type'] = 14;
			$map['form_id'] = $new[$i]['id'];
			$new[$i]['news'] = $m_cms_content->where($map)->order("time desc")->limit(1)->find();
		}
		$this->assign("new",$new);
		//dump($new);die;
		
		//查询合作伙伴
		//获得顶级分类
			$map['form_id'] = 0;
			$map['type'] = get_cms_model_conf('CMS_CAROUSELCLASS');
			$map['status'] = 1;
			
			$list = $m_cms_content->where($map)->order('sort desc')->select();
			
			//获得下级分类即商品数量
			foreach($list as $i=>$k){
				$down_map['form_id'] = $list[$i]['id'];
				$down_map['type'] = get_cms_model_conf('CMS_CAROUSELCLASS');
				$down_map['status']  =1;
				$down_list = $m_cms_content->where($down_map)->order('sort desc')->select();
			
				$list[$i]['down'] = $down_list;
				foreach($list[$i]['down'] as $d=>$v){
				
					$down_map['form_id'] = $list[$i]['down'][$d]['id'];
					$down_map['type'] = get_cms_model_conf('CMS_CAROUSELCLASS');
					$down_map['status']  =1;
					$down_lista = $m_cms_content->where($down_map)->order('sort desc')->select();
					//dump($down_lista);
					$list[$i]['down'][$d]['one'] = $down_lista;
					foreach($down_lista as $q=>$e){
						$map_one['form_id'] = $e['id'];
						$map_one['type'] = get_cms_model_conf('CMS_CAROUSEL');
						$map_one['status']  =1;
						if($q == 0 || $q ==2){
							$images = $m_cms_content->where($map_one)->order('time desc')->limit(2)->select();
						}else{
							$images = $m_cms_content->where($map_one)->order('time desc')->limit(4)->select();
						}
						
						$list[$i]['down'][$d]['one'][$q]['images'] = $images;
					}
				
				}
				
			}
			
		//dump($list[1]['down'][0]['one']);die;
		$this->assign("list",$list[1]['down'][0]['one']);
		
		$this->display();
	}
	
	/**
	 * 关于龙腾 
	 */
    public function About(){
		$m_cms_content = M('cms_content');
		if(IS_POST){
			$data = I();
			$data['type'] = 29;//在线留言
			$data['status'] = 1;
			$data['time'] = time();
			$result = $m_cms_content->add($data);
			if($result){
				$this->success("留言成功",U('Stage/Phone/About/form_id/231'));
			}else{
				$this->success("留言失败",U('Stage/Phone/About/form_id/231'));
			}
		}else{
			$map['form_id'] = 0;
			$map['type'] = 21;//新闻资讯下的分类
			$map['status'] = 1;
			$list = $m_cms_content->where($map)->order('sort desc')->select();//左侧分类栏
			$id = $list[0]['id'];//
			$form_id = I('form_id');
			$form_id=$form_id?$form_id:$id;
			$fmap['id'] = $form_id;
			$form = $m_cms_content->where($fmap)->find();//该内容分类详情
			
			$map['form_id'] = $form_id;
			$map['type'] = 22;//新闻资讯下的内容
			$_GET['p']=$_GET['p']?$_GET['p']:1;
			$list_new = $m_cms_content->where($map)->order('time desc')->limit(1)->find();
			
			$this->assign('pages',$show);
			
			/* dump($form);
			dump($list);
			dump($list_new);
			die; */
			$this->assign("list_new",$list_new);
			$this->assign("list",$list);
			$this->assign("form_id",$form_id);
			$this->assign("form",$form);
			$this->display();
		}
	}
	
	/**
	 * 关于龙腾   
	 */
    public function Honor(){
		
		
		$this->display();
	}
	
	/**
	 * 关于龙腾   合作伙伴
	 */
    public function Partner(){
		
		
		$this->display();
	}
	
	/**
	 * 关于龙腾   企业文化
	 */
	 
    public function Culture(){
		
		
		$this->display();
	}
	
	/**
	 * 新闻资讯   新闻列表
	 */
	 
    public function New_list(){
		$m_cms_content = M('cms_content');
		
		
		
		$map['form_id'] = 0;
		$map['type'] = 13;//新闻资讯下的分类
		$map['status'] = 1;
		$list = $m_cms_content->where($map)->order('sort desc')->select();//左侧分类栏
		$id = $list[0]['id'];//
		$form_id = I('form_id');
		$form_id=$form_id?$form_id:$id;
		$fmap['id'] = $form_id;
		$form = $m_cms_content->where($fmap)->find();//该内容分类详情
		
		$map['form_id'] = $form_id;
		$map['type'] = 14;//新闻资讯下的内容
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list_new = $m_cms_content->where($map)->order('time desc')->page($_GET['p'].',5')->select();
		
		$count      = $m_cms_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		
		/* dump($form);
		dump($list);
		dump($list_new);
		die; */
		
		$this->assign("list_new",$list_new);
		$this->assign("list",$list);
		$this->assign("form",$form);
		$this->display();
	}
	
	/**
	 * 新闻资讯   新闻详情
	 */
    public function New_details(){
		$m_cms_content = M('cms_content');
		
		$map['form_id'] = 0;
		$map['type'] = 13;//新闻资讯下的分类
		$map['status'] = 1;
		$list = $m_cms_content->where($map)->order('sort desc')->select();//左侧分类栏
		$id = $list[0]['id'];//
		$form_id = I('form_id');
		$form_id=$form_id?$form_id:$id;
		$fmap['id'] = $form_id;
		$form = $m_cms_content->where($fmap)->find();//该内容分类详情
		
		//资讯详情
		$id_map['id'] = I('param.id');
		$new = $m_cms_content->where($id_map)->find();//资讯详情
		$m_cms_content->where($id_map)->setInc("hints");//点击量
		
		//相关新闻。按点击量排
		$new_map['form_id'] = $form_id;
		$list_news = $m_cms_content->where($new_map)->order("hints desc")->limit(3)->select();
		
		$this->assign("list_news",$list_news);
		$this->assign("new",$new);
		$this->assign("list",$list);
		$this->assign("form",$form);
		$this->display();
	}
	
	/**
	 * 行业案例   视频列表
	 */
    public function Case_list(){
		$m_cms_content = M('cms_content');
		
		$map['form_id'] = 0;
		$map['type'] = 19;//行业案例下的分类
		$map['status'] = 1;
		$list = $m_cms_content->where($map)->order('sort desc')->select();//左侧分类栏
		$id = $list[0]['id'];//
		$form_id = I('form_id');
		$form_id=$form_id?$form_id:$id;
		$fmap['id'] = $form_id;
		$form = $m_cms_content->where($fmap)->find();//该内容分类详情
		
		$map['form_id'] = $form_id;
		$map['type'] = 20;//行业案例下的内容
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list_new = $m_cms_content->where($map)->order('time desc')->page($_GET['p'].',5')->select();
		
		$count      = $m_cms_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		
		/* dump($form);
		dump($list);
		dump($list_new);
		die; */
		$this->assign("list_new",$list_new);
		$this->assign("list",$list);
		$this->assign("form",$form);
		$this->display();
	}
	
	/**
	 * 解决方案   方案列表
	 */
    public function Scheme_list(){
		$m_cms_content = M('cms_content');
		$map['form_id'] = 0;
		$map['type'] = 15;//解决方案下的分类
		$map['status'] = 1;
		$list = $m_cms_content->where($map)->order('sort desc')->select();//左侧分类栏
		$id = $list[0]['id'];//
		$form_id = I('form_id');
		$form_id=$form_id?$form_id:$id;//默认模具行业ERP
		$fmap['id'] = $form_id;
		$form = $m_cms_content->where($fmap)->find();//该内容分类详情
		
		$map['form_id'] = $form_id;
		$map['type'] = 16;//解决方案下的内容
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list_new = $m_cms_content->where($map)->order('time desc')->page($_GET['p'].',5')->select();
		
		$count      = $m_cms_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		
		/* dump($form);
		dump($list);
		dump($list_new);
		die; */
		
		$this->assign("list_new",$list_new);
		$this->assign("list",$list);
		$this->assign("form",$form);
		$this->display();
	}
	
	/**
	 * 解决方案   方案详情
	 */
    public function Scheme_details(){
		$m_cms_content = M('cms_content');
		$map['form_id'] = 0;
		$map['type'] = 15;//新闻资讯下的分类
		$map['status'] = 1;
		$list = $m_cms_content->where($map)->order('sort desc')->select();//左侧分类栏
		$id = $list[0]['id'];//
		$form_id = I('form_id');
		$form_id=$form_id?$form_id:$id;
		$fmap['id'] = $form_id;
		$form = $m_cms_content->where($fmap)->find();//该内容分类详情
		
		//方案详情
		$id_map['id'] = I('param.id');
		$new = $m_cms_content->where($id_map)->find();//方案详情
		
		$this->assign("new",$new);
		$this->assign("list",$list);
		$this->assign("form",$form);
		$this->display();
	}
	
	/**
	 * 产品介绍   介绍列表
	 */
    public function Product_list(){
		$m_cms_content = M('cms_content');
		
		$map['form_id'] = 0;
		$map['type'] = 17;//产品介绍下的分类
		$map['status'] = 1;
		$list = $m_cms_content->where($map)->order('sort desc')->select();//左侧分类栏
		$id = $list[0]['id'];//
		$form_id = I('form_id');
		$form_id=$form_id?$form_id:$id;//MES系统
		
		$fmap['id'] = $form_id;
		$form = $m_cms_content->where($fmap)->find();//该内容分类详情
		
		$map['form_id'] = $form_id;
		$map['type'] = 18;//产品介绍下的内容
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list_new = $m_cms_content->where($map)->order('time desc')->page($_GET['p'].',3')->select();
		
		$count      = $m_cms_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,3);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		
		/* dump($form);
		dump($list);
		dump($list_new);
		die; */
		
		$this->assign("list_new",$list_new);
		$this->assign("list",$list);
		$this->assign("form",$form);
		$this->display();
	}
	
	/**
	 * 产品介绍   介绍详情
	 */
    public function Product_details(){
		$m_cms_content = M('cms_content');
		
		$map['form_id'] = 0;
		$map['type'] = 17;//新闻资讯下的分类
		$map['status'] = 1;
		$list = $m_cms_content->where($map)->order('sort desc')->select();//左侧分类栏
		$id = $list[0]['id'];//
		$form_id = I('form_id');
		$form_id=$form_id?$form_id:$id;
		$fmap['id'] = $form_id;
		$form = $m_cms_content->where($fmap)->find();//该内容分类详情
		
		//方案详情
		$id_map['id'] = I('param.id');
		$new = $m_cms_content->where($id_map)->find();//方案详情
		
		$this->assign("new",$new);
		$this->assign("list",$list);
		$this->assign("form",$form);
		$this->display();
	}
	
	/**
	 * 服务支持
	 */
    public function Serve(){
		$m_cms_content = M('cms_content');
		if(IS_POST){
			$data = I();
			$data['type'] = 29;//在线留言
			$data['status'] = 1;
			$data['time'] = time();
			$result = $m_cms_content->add($data);
			if($result){
				$this->success("留言成功",U('Stage/Phone/Serve/form_id/251'));
			}else{
				$this->success("留言失败",U('Stage/Phone/Serve/form_id/251'));
			}
		}else{
			$map['form_id'] = 0;
			$map['type'] = 23;//服务支持下的分类
			$map['status'] = 1;
			$list = $m_cms_content->where($map)->order('sort desc')->select();//左侧分类栏
			$id = $list[0]['id'];//
			$form_id = I('form_id');
			$form_id=$form_id?$form_id:$id;
			$fmap['id'] = $form_id;
			$form = $m_cms_content->where($fmap)->find();//该内容分类详情
			
			$map['form_id'] = $form_id;
			$map['type'] = 24;//服务支持下的内容
			$_GET['p']=$_GET['p']?$_GET['p']:1;
			$list_new = $m_cms_content->where($map)->order('time desc')->limit(1)->find();
			
			$this->assign('pages',$show);
			
			/* dump($form);
			dump($list);
			dump($list_new);
			die; */
			
			$this->assign("list_new",$list_new);
			$this->assign("list",$list);
			$this->assign("form",$form);
			$this->assign("form_id",$form_id);
			$this->display();
		}
	}
	
	
	public function isMobile()
 { 
    // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
    if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
    {
        return true;
    } 
    // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
    if (isset ($_SERVER['HTTP_VIA']))
    { 
        // 找不到为flase,否则为true
        return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
    } 
    // 脑残法，判断手机发送的客户端标志,兼容性有待提高
    if (isset ($_SERVER['HTTP_USER_AGENT']))
    {
        $clientkeywords = array ('nokia',
            'sony',
            'ericsson',
            'mot',
            'samsung',
            'htc',
            'sgh',
            'lg',
            'sharp',
            'sie-',
            'philips',
            'panasonic',
            'alcatel',
            'lenovo',
            'iphone',
            'ipod',
            'blackberry',
            'meizu',
            'android',
            'netfront',
            'symbian',
            'ucweb',
            'windowsce',
            'palm',
            'operamini',
            'operamobi',
            'openwave',
            'nexusone',
            'cldc',
            'midp',
            'wap',
            'mobile'
            ); 
        // 从HTTP_USER_AGENT中查找手机浏览器的关键字
        if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
        {
            return true;
        } 
    } 
    // 协议法，因为有可能不准确，放到最后判断
    if (isset ($_SERVER['HTTP_ACCEPT']))
    { 
        // 如果只支持wml并且不支持html那一定是移动设备
        // 如果支持wml和html但是wml在html之前则是移动设备
        if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
        {
            return true;
        } 
    } 
    return false;
 } 
}